package com.groupnections.server.database.problem;

import java.util.ArrayList;
import java.util.List;

import com.google.appengine.api.datastore.Text;
import com.groupnections.shared.entities.Tags;

public class ConvertProblemToDatabase {

	public static List<Problem> getDatabaseProblems(
			List<com.groupnections.shared.entities.Problem> problems,
			String tags) {

		List<Problem> problemsDatabase = new ArrayList<Problem>();

		for (com.groupnections.shared.entities.Problem problem : problems) {

			Problem problemDatabase = new Problem();
			problemsDatabase.add(getDatabaseProblem(problemDatabase, problem,
					tags));
		}

		return problemsDatabase;
	}

	public static Problem getDatabaseProblem(Problem problemDatabase,
			com.groupnections.shared.entities.Problem problem, String tags) {

		problemDatabase.setDescription(new Text(problem.getDescription()));

		problemDatabase.setTags(new Text(Tags.getStaticTags(
				problem.getDescription(), tags)));

		return problemDatabase;
	}
}
